﻿var urlcore = 'http://127.0.0.1:8088';
// var urlcore = 'http://wx.biying.name/interface';
// var urlcore = 'https://APP.MIDUU.COM/interface';
// var urlcore = 'http://app.jiagangwangluo.com/midudu/';
//var urlcore = 'http://hdf.ivs.org.cn/interface';
var pageSize = 8;
//从url中获取参数值
function getvl(name) {
    var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
    if (reg.test(location.href.trim())) return unescape(RegExp.$2.replace(/\+/g, " "));
    return "";
};

var CMCC = /(^((13[4-9]{1})|(147)|(15[0-2]{1})|(15[7-9]{1})|(178)|(18[2-4]{1})|(18[7-8]{1}))\d{8}$)|(^((1703)|(1705)|(1706))\d{7}$)/;//中国移动
var CUCC = /(^((13[0-2]{1})|(145)|(155)|(156)|(171)|(175)|(176)|(185)|(186))\d{8}$)|(^(170[7-9]{1})\d{7}$)/;//中国联通
var CTCC = /(^((133)|(149)|(153)|(173)|(177)|(180)|(181)|(189)|(199))\d{8}$)|(^(170[0-2]{1})\d{7}&)/;//中国电信

//设置全局ajax
$.ajaxSetup({
    xhrFields: {
    	withCredentials: true
	}
});

$(function() {
	//时间格式化
	Date.prototype.pattern=function(fmt) {
	    var o = {
	    "M+" : this.getMonth()+1, //月份         
	    "d+" : this.getDate(), //日         
	    "h+" : this.getHours(), //小时         
	    "H+" : this.getHours(), //小时         
	    "m+" : this.getMinutes(), //分         
	    "s+" : this.getSeconds(), //秒         
	    "q+" : Math.floor((this.getMonth()+3)/3), //季度         
	    "S" : this.getMilliseconds() //毫秒         
	    };         
	    var week = {         
	    "0" : "/u65e5",         
	    "1" : "/u4e00",         
	    "2" : "/u4e8c",         
	    "3" : "/u4e09",         
	    "4" : "/u56db",         
	    "5" : "/u4e94",         
	    "6" : "/u516d"        
	    };         
	    if(/(y+)/.test(fmt)){         
	        fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));         
	    }         
	    if(/(E+)/.test(fmt)){         
	        fmt=fmt.replace(RegExp.$1, ((RegExp.$1.length>1) ? (RegExp.$1.length>2 ? "/u661f/u671f" : "/u5468") : "")+week[this.getDay()+""]);         
	    }         
	    for(var k in o){         
	        if(new RegExp("("+ k +")").test(fmt)){         
	            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));         
	        }         
	    }         
	    return fmt;         
	}
});

/**
 * 时间格式化
 */
function formatDate(dateTime,format){
	return new Date(dateTime).pattern(format); 
}

/**
 * 性别状态
 * @param {Object} status
 */
function sexToName(type){
	if(type==1){
		return "先生";
	}
	if(type==2){
		return "女士";
	}
	return "";
}



function  areaTypeName2(type){var area = "";
$.ajax({
	url: urlcore + "/api/product/selectPlace?areaId=" + type,
	type: "post",
	dataType: 'json',
	contentType: "application/json;charset=utf-8",
	data: JSON.stringify(formData),
	success: function(data) {
		if(data.success == true) {
			area = data.data;
		} else {
			alert(data.msg);
		}

	},
	error: function() {
		/* Act on the event */
		/*alert("error");*/
	}
});
return area;}







 //初始化fileinput控件（第一次初始化）
function initFileInput(ctrlName, uploadUrl,okName,maxnNum) {    
    var control = $('#' + ctrlName); 

    control.fileinput({
        language: 'zh', //设置语言
        uploadUrl: uploadUrl, //上传的地址
        //uploadExtraData:{"id": 1, "fileName":'123.mp3'},
        resizeImage: true,
        resizePreference: 'width',
        resizeImageQuality: 0.2,
        uploadAsync: true, //默认异步上传
        showUpload: true, //是否显示上传按钮
        showRemove : true, //显示移除按钮
        showPreview : true, //是否显示预览
        showCaption: false,//是否显示标题
        browseClass: "btn btn-primary", //按钮样式     
        dropZoneEnabled: true,//是否显示拖拽区域
        maxFileCount: 10, //表示允许同时上传的最大文件个数
        dropZoneTitle: '拖拽文件到这里 &hellip;',
        enctype: 'multipart/form-data',
        validateInitialCount:true,
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
    }).on("fileuploaded", function(event, data,key) {
        if(data.response){	
        	var okData = data.response.data;
        	for (var i = 0; i < okData.length; i++) {
        		var strHtml = 
		            	'<div style="position:relative;width:250px;height:250px;float:left;display:none" id="'+key+'">'+
		            	'	<span onclick="removeStrHtml()" style="position:absolute;top:10px;right:10px;font-size:20px;color:#f00;" class="glyphicon glyphicon-trash" aria-hidden="true">'+
		            	'	</span>'+
		            	'	<img style="padding: 5px 5px 5px 5px;" width="250px" height="250px" src="'+okData[i]+'">'+
		        		'</div>';
		        $(okName).append(strHtml);
        	}
        }
    }).on('filesuccessremove', function(event, key) { 
    	$("#"+key).remove();  
	});
}

/**
 * 获取fileinput的图片地址
 */
function fileInputImgUrl(noteObj){
	var urls = "";
    $("#"+noteObj+" img").each(function(index,item){
		urls += $(this).attr("src")+"*";
	});
	if(urls!=""){
		  urls = urls.substring(0, urls.length-1);
	}
	return urls;
}


/**
 * 获取fileinput的图片地址
 */
function initFileInputImgUrl(imgUrls){
	var imgStr = '';
    if (imgUrls != null && imgUrls != '') {
        var imgarr = imgUrls.split("*");
        $.each(imgarr,function(index,value){
            imgStr += 
           		'<div style="position:relative;width:250px;height:250px;float:left;" display="block">'+
            	'	<span onclick="removeStrHtml(this)" style="position:absolute;top:10px;right:10px;font-size:20px;color:#f00;" class="glyphicon glyphicon-trash" aria-hidden="true">'+
            	'	</span>'+
            	'	<img style="padding: 5px 5px 5px 5px;" width="250px" height="250px" src="'+value+'">'+
        		'</div>';
		 });
    }
	return imgStr;
}


/**
 * 移除Html代码
 */
function removeStrHtml(obj){
	$(obj).parent().remove();
}

/**
 * 分页id,翻页连续
 */
function pageIndex(pageNo,pageSize,i){
	return (pageNo-1)*pageSize+i+1;
}


/**
 * 判断手机格式是否正确
 * @param {Object} obj
 */
function checkMobile(phone){  
	//匹配移动手机号
	var PATTERN_CHINAMOBILE = /^1(3[4-9]|5[012789]|8[23478]|4[7]|7[8])\d{8}$/;
	// 匹配联通手机号
	var PATTERN_CHINAUNICOM =/^1(3[0-2]|5[56]|8[56]|4[5]|7[6])\d{8}$/;
	// 匹配电信手机号
	var PATTERN_CHINATELECOM =/^1(3[3])|(8[019])|(53)|(77)\d{8}$/;
    if(PATTERN_CHINAMOBILE.test(phone) || PATTERN_CHINAUNICOM.test(phone) || PATTERN_CHINATELECOM.test(phone)){  
        return true;  
    }else{  
    	alert("手机格式错误！");
        return false;  
    }  
}  
